package servidor.run.paneles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;

import dominio.beans.Proveedor;

import servicio.ServidorImp;

public class AltaProveedor extends JPanel {

	/**
	 * Create the panel.
	 * @param servidor 
	 */
	public AltaProveedor(final ServidorImp servidor) {

		JLabel lblRazonSocial = new JLabel("Razon Social");
		final JTextField txtRazonSoc;
		final JTextField txtCuil;
		JLabel lblCuil = new JLabel("Cuil");
		
		txtRazonSoc = new JTextField();
		txtRazonSoc.setColumns(10);
		
		txtCuil = new JTextField();
		txtCuil.setColumns(10);
		
		JButton btnAgregarProveedor = new JButton("Agregar Proveedor");
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblCuil, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtCuil))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblRazonSocial)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(txtRazonSoc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnAgregarProveedor)
					.addContainerGap(177, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblRazonSocial)
						.addComponent(txtRazonSoc, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnAgregarProveedor))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCuil)
						.addComponent(txtCuil, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(223, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
		/**
		 * Eventos
		 */
		btnAgregarProveedor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Proveedor p = new Proveedor();
				p.setNroCuiL(txtCuil.getText());
				p.setRazonSocial(txtRazonSoc.getText());
				servidor.altaProveedor(p);
				
			}
		});

	}
}


